package protobuf.Serialization;

import component.userInformation.ChatMsg;
import myClient.session.ClientSession;
import protobuf.protoClass.ProtoMsg;

public class ChatMsgConverter extends BaseConverter {

    /**
     * {@link ProtoMsg.Message} 中 MessageRequest 字段
     */
    public ChatMsgConverter(ClientSession session) {
        super(ProtoMsg.HeadType.MESSAGE_REQUEST, session);
    }

    /**
     * 静态方法
     *
     * @param chatMsg       聊天信息类
     * @param clientSession Session
     * @return 聊天信息 protoBuf类型
     */
    public static ProtoMsg.Message build(ChatMsg chatMsg, ClientSession clientSession) {
        return new ChatMsgConverter(clientSession).build(chatMsg);
    }

    /**
     * 设置 ProtoMsg.Message第 6个字段：MessageRequest ，
     * 并调用 build()方法，创建 ProtoMsg.Message
     */
    public ProtoMsg.Message build(ChatMsg chatMsg) {

        //构建 ProtoMsg.MessageRequest
        ProtoMsg.MessageRequest.Builder requestBuilder = ProtoMsg.MessageRequest.newBuilder();

        //通过 ChatMsg类设置 ProtoMsg.MessageRequest 内容
        chatMsg.setProtoRequestMsg(requestBuilder);

        //将信息序列号设置为 -1
        return get_ProtoMsg_Message_Builder_withThreeFields(-1) // ProtoMsg.Message前三个字段
                .setMessageRequest(requestBuilder)      //ProtoMsg.Message第 6个字段：MessageRequest IM消息请求
                .build();
    }

}
